package com.k8.common.adaptive;

import com.k8.common.JdkAdaptiveProxy;
import com.k8.common.factroy.loader.ExtensionLoader;

import java.lang.reflect.Proxy;
import java.util.Map;

public class AdaptiveProxyFactory {
    public static Object crateAdaptiveProxy(String policy, Object target, ExtensionLoader<?> extensionLoader, Map<Integer, Integer> candidateAdaptiveParaReflectMap) {
        Class<?> clazz = target.getClass();
        Class<?>[] interfaces = clazz.getInterfaces();
        if ("jdk".equals(policy) && interfaces.length != 0) {
            JdkAdaptiveProxy jdkAdaptiveProxy = new JdkAdaptiveProxy(extensionLoader, target, candidateAdaptiveParaReflectMap);
            return Proxy.newProxyInstance(target.getClass().getClassLoader(), interfaces, jdkAdaptiveProxy);
        }
        return null;
    }
}
